package cn.xf.controller;

import cn.xf.domain.Permission;
import cn.xf.domain.UserInfo;
import cn.xf.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author xiaofu
 * @date 2021-05-18 12:22
 * @email dearaf@163.com
 */
@RequestMapping("/permission")
@Controller
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        List<Permission> permissionList = permissionService.findAllByPage(page,pageSize);
        PageInfo<Permission> pageInfo = new PageInfo<Permission>(permissionList);
        ModelAndView mv = new ModelAndView();
        mv.addObject("pageInfo", pageInfo);
        mv.setViewName("/permission/permission-list");
        return mv;
    }

    @RequestMapping("/save.do")
    public String save(Permission permission)  {
        permissionService.save(permission);
        return "redirect:findAll.do";
    }
}
